       /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package InformacnaStruktura;

/**
 *
 * @author MartinaHlinková
 */
public class CasBezDatumu implements Comparable<CasBezDatumu>{
    private int hodiny;
    private int minuty;
    
    public CasBezDatumu(int hodiny, int minuty){
        this.hodiny = hodiny;
        this.minuty = minuty;
    }
    
    public CasBezDatumu(int minuty){
        this.hodiny =(int) minuty/60;
        this.minuty = minuty%60;
    }
    
    @Override
    public String toString(){
        return ""+ Integer.toString(this.getHodiny())+":"+Integer.toString(this.getMinuty());
    }
    
    public int getHodiny(){
        return this.hodiny;
    }
    
    public int getMinuty(){
        return this.minuty;
    }

    @Override
    public int compareTo(CasBezDatumu o) {
        if(this.hodiny > o.hodiny){
            return (+1);
        }else if(this.hodiny < o.hodiny){
            return (-1);
        }else{
            if(this.minuty > o.minuty){
                return (+1);
            }else if(this.minuty < o.minuty){
                return (-1);
            }else{
                return 0;
            }
        }
    }
    public boolean after(CasBezDatumu o){
        if(this.compareTo(o)== 1) return true;
        else return false;
    }
    
    public boolean before(CasBezDatumu o){
        if(this.compareTo(o)== -1) return true;
        else return false;
    }
    
   

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CasBezDatumu other = (CasBezDatumu) obj;
        if (this.hodiny != other.hodiny) {
            return false;
        }
        if (this.minuty != other.minuty) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 13;
        hash = 31 * hash + this.hodiny;
        hash = 31 * hash + this.minuty;
        return hash;
    }
    
    public static int celkovyPocetMinut(CasBezDatumu cas){
        int navrat = 0;
        
        navrat = cas.getHodiny()*60+cas.getMinuty();
        
        return navrat;
    }
    
    public static int zmerajCasNaMinuty(CasBezDatumu casOd,CasBezDatumu casDo  ){
        int navrat = 0;
        if(casOd == null || casDo == null)return -1;
        if(casOd.before(casDo) == true){
            navrat = (casDo.getHodiny() - casOd.getHodiny())*60;
            navrat = navrat +(casDo.getMinuty() - casOd.getMinuty());
            
        }else if(casOd.after(casDo)== true){
            navrat = (23 - casOd.getHodiny())*60 + (60 - casOd.getMinuty());
            navrat = navrat + (casDo.getHodiny()*60 + casDo.getMinuty());
            
        }
        
        return navrat;
    }
    public static void main(String args[]){
        System.out.println("Test meraica minut");
        System.out.println("Od 7:00 do 15:00");
        int kontrola = InformacnaStruktura.CasBezDatumu.zmerajCasNaMinuty(
                new InformacnaStruktura.CasBezDatumu(7,0), new InformacnaStruktura.CasBezDatumu(15,0));
        
        System.out.println("Pocet minut: " +kontrola+" spravne je "+(8*60));
        
        System.out.println("Od 22:00 do 6:00");
        kontrola = InformacnaStruktura.CasBezDatumu.zmerajCasNaMinuty(
                new InformacnaStruktura.CasBezDatumu(22,0), new InformacnaStruktura.CasBezDatumu(6,0));
        
        System.out.println("Pocet minut: " +kontrola+" spravne je "+(8*60));
        
        System.out.println("Od 7:30 do 12:45");
        kontrola = InformacnaStruktura.CasBezDatumu.zmerajCasNaMinuty(
                new InformacnaStruktura.CasBezDatumu(7,30), new InformacnaStruktura.CasBezDatumu(12,45));
        
        System.out.println("Pocet minut: " +kontrola+" spravne je "+(4*60+45+30));
        
        
    }
}
